package iha.auh.kds.aba.painratingapp;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RadioButton;
import android.widget.TextView;

public class SimplePainRatingFragment extends Fragment implements View.OnClickListener {
	public SimplePainRatingFragment() {
		// Required empty public constructor
	}
	
	private RadioButton buttons[];
	private TextView score;
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		View view = inflater.inflate(R.layout.fragment_simple_pain_rating, container, false);
		score = (TextView) view.findViewById(R.id.simple_pain_rating_score);
		
		buttons = new RadioButton[6];
		buttons[0] = (RadioButton) view.findViewById(R.id.radiobtn_simple_painrating_0);
		buttons[1] = (RadioButton) view.findViewById(R.id.radiobtn_simple_painrating_2);
		buttons[2] = (RadioButton) view.findViewById(R.id.radiobtn_simple_painrating_4);
		buttons[3] = (RadioButton) view.findViewById(R.id.radiobtn_simple_painrating_6);
		buttons[4] = (RadioButton) view.findViewById(R.id.radiobtn_simple_painrating_8);
		buttons[5] = (RadioButton) view.findViewById(R.id.radiobtn_simple_painrating_10);
		buttons[0].setOnClickListener(this);
		buttons[1].setOnClickListener(this);
		buttons[2].setOnClickListener(this);
		buttons[3].setOnClickListener(this);
		buttons[4].setOnClickListener(this);
		buttons[5].setOnClickListener(this);
		
//		TextView childName = (TextView) view.findViewById(R.id.child_name_textview);
//		ChildModel child = ChildSingleton.getChild();
//		if (child != null)
//			childName.setText(child.Name);
		return view;
	}
	
	@Override
	public void onClick(View v){
		for(RadioButton btn : buttons){
			btn.setChecked(false);
		}
		
		switch(v.getId()){
		case R.id.radiobtn_simple_painrating_0:
			buttons[0].setChecked(true);
			score.setText("0");
			break;
		case R.id.radiobtn_simple_painrating_2:
			buttons[1].setChecked(true);
			score.setText("2");
			break;
		case R.id.radiobtn_simple_painrating_4:
			buttons[2].setChecked(true);
			score.setText("4");
			break;
		case R.id.radiobtn_simple_painrating_6:
			buttons[3].setChecked(true);
			score.setText("6");
			break;
		case R.id.radiobtn_simple_painrating_8:
			buttons[4].setChecked(true);
			score.setText("8");
			break;
		case R.id.radiobtn_simple_painrating_10:
			buttons[5].setChecked(true);
			score.setText("10");
			break;
		default:
			break;
		
		}
	}
}
